<template>
    <div class="app-container">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>项目日报评审人设置</span>
            </div>

            <el-table
                    :data="reviews"
                    border
                    size="small"
                    :header-cell-style="tableHeaderStyle"
                    style="width: 100%">
                <el-table-column
                        fixed
                        label="No."
                        type="index"
                        header-align="center"
                        align="center"
                        width="80">
                    <template slot-scope="scope">
                        {{ (page.pageNum - 1) * page.pageSize + scope.$index + 1 }}
                    </template>
                </el-table-column>
                <el-table-column
                        fixed
                        prop="userName"
                        label="成员"
                        header-align="center"
                        align="center"
                        min-width="150">
                </el-table-column>
                <el-table-column
                        prop="deptName"
                        label="部门"
                        header-align="center"
                        :show-overflow-tooltip="true"
                        align="center"
                        min-width="150">
                </el-table-column>
                <el-table-column
                        prop="proroleName"
                        label="项目角色"
                        header-align="center"
                        align="center"
                        min-width="120">
                </el-table-column>
                <el-table-column
                        prop="reviewName"
                        label="日志评审人"
                        header-align="center"
                        align="center"
                        min-width="120">
                </el-table-column>
                <el-table-column
                        fixed="right"
                        label="操作"
                        align="center"
                        header-align="center"
                        width="120">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                @click="setReviewer(scope.row)"
                                size="small">设置
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页-->
            <div style="text-align:right;margin: 15px;margin-right: 0px">
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :page-size="page.pageSize"
                        :current-page="page.pageNum"
                        @current-change="changeCurrentPage"
                        :total="page.pageCount">
                </el-pagination>
            </div>

            <UserList
                    ref="userList"
                    :isShowSearch="false"
                    :id="currentReviewId"
                    @handleChose="setReviewerProManager"
                    />
        </el-card>
    </div>

</template>

<script>
    import {
        http_review_list,
        http_update_review
    } from '@/api/review'
    import { tableHeaderStyle } from '@/utils/constant'
    import UserList from '@/components/userList/index'
    import { Message } from 'element-ui'

    export default {
        data(){
            return{
                tableHeaderStyle,
                reviews: [],
                currentReviewId: null,
                page: {
                    pageNum: null,
                    pageSize: null,
                    pageCount: null,
                },

            }
        },
        components:{
            UserList
        },
        methods:{
            http_list(){
                let proId = this.$route.query.proId
                http_review_list(this.page,proId).then(result=>{
                    // console.log("result",result)
                    const {data} = result
                    this.reviews = data.records
                    this.page = {
                        pageNum: data.current,
                        pageSize: data.size,
                        pageCount: data.total,
                    }
                })
            },
            http_update(params){
                http_update_review(params).then(result=>{
                    const {success,data,message} = result
                    if (success){
                        Message.success(message)
                        this.http_list()
                    }
                })
            },
            changeCurrentPage(val) {
                this.page.pageNum = val
                this.http_list()
            },
            setReviewer(review){
                this.review = review
                this.$refs.userList.centerDialogVisible2 = true
            },
            setReviewerProManager(user){
                let params = {
                    // id: this.review.id,
                    userId: this.review.userId,
                    reviewId: user.userId,
                    reviewName: user.userName,
                    proId: this.$route.query.proId
                }
                this.http_update(params)
            }
        },
        created() {
            this.http_list()
        }
    }
</script>



<style lang="less" scoped>
    .text {
        font-size: 14px;
    }
    .item {
        margin-bottom: 18px;
    }
    .clearfix:before,
    .clearfix:after {
        display: table;
        content: "";
    }
    .clearfix:after {
        clear: both
    }
    .box-card {
        width: 100%;
    }
</style>
